//Data Cleaning//
use "C:\Users\user\Desktop\objective2\stataobjective2Data.dta" 
br
//Coding Hospital//
tab casesources
tab controlsources
gen Hospital= controlsources
order Hospital controlsources
tab controlsources
replace Hospital=casesources if controlsources=="" & casesources!=""
save,replace
encode Hospital, gen (Hospital1)
codebook Hospital1
tab Hospital1
describe Hospital1
save,replace
tab Hospital1
//Encoding case//
codebook case
gen Case1=1 if case=="Yes"
replace Case1=0 if case=="No"
tab Case1
label define Casc 1 "Yes" 0 "No"
label values Case1 Casc
codebook Case1
save,replace
tab Case1
tab sbd1

//MATERNAL OCCUPATION//

/Mothers Occupation//
tab mat_occup
gen Mat_Occupation1=1 if mat_occup=="farmer"
replace Mat_Occupation1=2 if mat_occup=="employed"
replace Mat_Occupation1=3 if mat_occup=="unemployed"
tab Mat_Occupation1
save,replace
label define B 1 "farmer" 2 "employed" 3 "unemployed"
label values Mat_Occupation1 B
codebook Mat_Occupation1
save,replace
tab Mat_Occupation1 Case1, col
logit Case1 i.Mat_Occupation1
logit, or



///GENERATING AND UNIVARIABLE ANALYSIS OF SOCIODEMOGRAPHIC FACTORS///
//MATERNAL AGE//
tab mat_age
sum mat_age
gen matage = mat_age
replace matage = 1 if (mat_age <=34)
replace matage = 2 if (mat_age >=35)
codebook matage
tab matage Case1, col
describe matage
tab matage
logit Case1 matage
logit, or
logit Case1 ib2.matage
logit, or

//MAT CASEAGE//
tab caseage
sum caseage

//MAT CONTROLAGE//
tab controlage
sum controlage

//MATERNAL EDUCATION LEVEL//
tab mat_educ
gen Mat_Education1=1 if mat_educ=="None"
replace Mat_Education1=2 if mat_educ=="Primary"
replace Mat_Education1=3 if mat_educ=="Secondary"
replace Mat_Education1=4 if mat_educ=="College Certificate"
replace Mat_Education1=5 if mat_educ=="College Diploma"
replace Mat_Education1=6 if mat_educ=="University Degree"
tab Mat_Education1
label define D 1 "None" 2 "Primary" 3 "Secondary" 4 "College Certificate" 5 "College Diploma" 6 "University Degree"
label values Mat_Education1 D
codebook Mat_Education1
save,replace
tab Mat_Education1
codebook Mat_Education1
gen MaternalEducation12=1 if Mat_Education1==1|Mat_Education1==2
replace MaternalEducation12=2 if Mat_Education1==3
replace MaternalEducation12=3 if Mat_Education1>3 & Mat_Education1!=.
tab MaternalEducation12
label define ma 1 "Primary and below" 2 "Secondary" 3 "Tertiary"
label values MaternalEducation12 ma
save,replace
codebook MaternalEducation12
tab MaternalEducation12 Case1,col
logit Case1 ib3.MaternalEducation12
logit, or


// GESTATIONAL AGE TO FIRST ANC VISIT//
tab gestwks_anc1
sum gestwks_anc1
gen gestwksanc1=1 if gestwks_anc1<=8
replace gestwksanc1=2 if gestwks_anc1>=9 & gestwks_anc1!=.
tab gestwksanc1
label define S 1 "<=8" 2 ">=9"
label values gestwksanc1 S
codebook gestwksanc1
label values gestwksanc1 S
codebook gestwksanc1
save,replace
tab gestwksanc1 
tab gestwksanc1 Case1, col
logit Case1 ib1.gestwksanc1
logi, or

//GESTATIONAL AGE OF CASES WEEKS TO 1ST ANC//
tab casegestwks
sum casegestwks

//GESTATIONAL AGE OF CONTROLS WEEKS TO 1ST ANC//
tab controlgestwks
sum controlgestwks

//PARITY//
tab gravidity
sum gravidity
gen Parity1=1 if gravidity==1
replace Parity1=2 if gravidity>=2 & gravidity!=.
tab Parity1
label define P 1 "=1" 2 ">1"
label values Parity1 p
codebook Parity1 Parity1
codebook Parity1
label values Parity1 P
codebook Parity1
save,replace
tab Parity1 
tab Parity1 Case1, col
logit Case1 Parity1
logit, or
logit Case1 ib1.Parity1
logit, or
tab Parity1

//PARITY OF CASES//
tab casegrav
sum casegrav

//PARITY OF CONTROLS//
tab controlgrav
sum controlgrav

//ANC BEGAN AFTER 8 WEEKS AFTER/POST CONCEPTION//
tab anc_lmp
tab anc_lmp
encode anc_lmp, gen(ANC_2monthsAfter)
codebook ANC_2monthsAfter
save,replace
tab anc_lmp Case1, col
tab ANC_2monthsAfter
logit Case1 i.ANC_2monthsAfter
logit, or


//GENERATING PRECONCEPTION FOLIC ACID INTAKE/ 3 MONTHS BEFORE LMP//
codebook fa_lmp
describe fa_lmp
tab fa_lmp
gen Folic_Acid= fa_lmp if fa_lmp!="Missing"
encode Folic_Acid,gen(Folic_Acid1)
tab Folic_Acid1
tab Folic_Acid1,m
tab Folic_Acid1 Case1, col
logit Case1 Folic_Acid1
logit, or
logit Case1 i.Folic_Acid1
logit, or

//GENERATING PESTICIDE-EXPOSURE//
tab farm_pest
encode farm_pest, gen (farm_pesticide)
codebook farm_pesticide
save,replace
tab farm_pesticide
tab farm_pesticide Case1, col
logit Case1 i.farm_pesticide
logit, or

///GENERATING AND ANALYSIS OF ENVIRONMENT-INHERITANCE INTERCTION FACTORS///
//GENERATING NATURE OF PREGNANCY//
tab preg_nature
encode preg_nature,gen(preg_nature1)
codebook preg_nature
codebook preg_nature1
save,replace
tab preg_nature1
tab preg_nature1 Case1, col
logit Case1 i.preg_nature1
logit, or
//GENERATING CHILD SEX//
tab child_sex
encode child_sex, gen(child_sex1)
codebook child_sex1
save,replace
tab child_sex1
tab child_sex1 Case1, col
logit Case1 i.child_sex1
logit, or

//GENERATING SIBLING WITH BIRTH DEFECTS//
tab child_defect
encode child_defect, gen (child_defect1)
codebook child_defect
codebook child_defect1
save,replace
tab child_defect1 Case1, col
logit Case1 i.child_defect1
logit, or
tab child_defect1

///GENERATING AND UNIVARIABLE ANALYSIS OF ENVIROMENT-RELATED TERATOGENS//
//Generating Chronic illness//
tab chronic_illness
encode chronic_illness, gen(chronic_illness1)
codebook chronic_illness1
save,replace
tab chronic_illness1
codebook chronic_illness1
gen chronic_illness12=1 if chronic_illness1==6
replace chronic_illness12=2 if chronic_illness1==8
replace chronic_illness12=3 if chronic_illness1!=6 & chronic_illness1!=8
tab chronic_illness12
label define chronic 1 "Hypertension" 2 "No chronic illness" 3 "Other chronic illness"
label values chronic_illness12 chronic
save,replace
logit Case1 ib2.chronic_illness12 
logit, or
tab chronic_illness12 Case1,col


///MULTIVARIABLE ANALAYSIS WITHOUT TERM//
logi Case1 ib1.Parity1 i.child_defect1 i.child_sex1 ib1.Parity1 i.farm_pesticide ib2.chronic_illness12 ib2.matage i.Folic_Acid1 i.preg_nature1
logit, or















